package com.yalonga.dc.examples.r2dbc.controller;

import com.yalonga.dc.examples.r2dbc.entity.User;
import com.yaolonga.dc.core.DCPage;
import com.yaolonga.dc.core.DcExecutorManager;
import com.yaolonga.dc.core.model.SearchModel;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yaolong
 * @version V1.0.0
 * @program dynamic-condition
 * @description
 * @create 2024-06-01 18:07
 **/
@RestController
@RequestMapping("/api")
@CrossOrigin
public class ConditionController {
    @RequestMapping("/page")
    public Mono<Map<String,Object>> page(@RequestBody SearchModel model){
        Mono<DCPage<User>> r2dbc = DcExecutorManager.getExecutor("r2dbc").executePageAsync(model, User.class);
        return r2dbc.map(i -> {
            HashMap<String, Object> map = new HashMap<>();
            map.put("result",i);
            return map;
        });
    }
}
